package com.wxlsoft.config.model;

import java.util.LinkedList;
import java.util.List;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class EsbProtocol {

	/**
	 * 协议ID
	 */
	private String id;
	
	/**
	 * 所属微服务应用名
	 */
	private String serviceName;
	
	/**
	 * 协议名称，展示协议名称
	 */
	private String protocolName;	
	
	/**
	 * 接入接出类型 s 接入， c 接出
	 */
	private String protocolAccessType;
	
	/**
	 * 访问类型
	 */
	private String packageType;	
	
	public static List<EsbProtocol> parse(JsonNode data) {
		List<EsbProtocol> result = new LinkedList<>();
		ArrayNode records = (ArrayNode) data.get("records");
		
		for (JsonNode record : records) {
			String id = record.get("id").asText();
			String serviceName = record.get("serviceName").asText();
			String protocolName = record.get("protocolName").asText();
			String protocolAccessType = record.get("protocolAccessType").asText();
			String packageType = record.get("packageType").asText();
			result.add(new EsbProtocol(id, serviceName, protocolName, protocolAccessType, packageType));
		}
		return result;
	}

	
}
